<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

use think\Config;
use think\Session;
use fast\Http;

class Jdycommon extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();

    }

    //http://acciot.test/api/jdycommon/getnotifyusers
    //知會人員 案场关联的
    public function getnotifyusers($anchang)
    {
        if (!$anchang) {
            return array();
        }

        $sql = "select a.*, g.group_id, gg.name as groupname";
        $sql .= " from fa_admin a left JOIN fa_auth_group_access g on a.id = g.uid left JOIN fa_auth_group gg on gg.id = g.group_id "
            . " where g.group_id in (2,8,10,7,5,9) ";
        $list = Db::query($sql);
        $list2 = [];
        foreach ($list as $row) {
            $anchangidlist = json_decode($row['anchangids'], TRUE);
            if ($anchangidlist && in_array($anchang->id, $anchangidlist)) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }

            if ($row['xzq1'] == $anchang->xzq
                || $row['xzq2'] == $anchang->xzq
                || $row['xzq3'] == $anchang->xzq
                || $row['xzq4'] == $anchang->xzq
                || $row['xzq5'] == $anchang->xzq
            ) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }

            if (($row['xianshi1'] == $anchang->xianshi && empty($row['xzq1']))
                || ($row['xianshi2'] == $anchang->xianshi && empty($row['xzq2']))
                || ($row['xianshi3'] == $anchang->xianshi && empty($row['xzq3']))
                || ($row['xianshi4'] == $anchang->xianshi && empty($row['xzq4']))
                || ($row['xianshi5'] == $anchang->xianshi && empty($row['xzq5']))
            ) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }
        }

        $list2 = array_unique($list2, SORT_REGULAR);

        return $list2;
    }

    //http://acciot.test/api/jdycommon/gethandleusers
    //指定處理人員 案场关联的
    public function gethandleusers($anchang)
    {
        if (!$anchang) {
            return array();
        }

        $sql = "select a.*, g.group_id, gg.name as groupname";
        $sql .= " from fa_admin a left JOIN fa_auth_group_access g on a.id = g.uid left JOIN fa_auth_group gg on gg.id = g.group_id "
            . " where g.group_id in (10, 7, 8) ";
        $list = Db::query($sql);
        $list2 = [];
        foreach ($list as $row) {
            $anchangidlist = json_decode($row['anchangids'], TRUE);
            if ($anchangidlist && in_array($anchang->id, $anchangidlist)) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }

            if ($row['xzq1'] == $anchang->xzq
                || $row['xzq2'] == $anchang->xzq
                || $row['xzq3'] == $anchang->xzq
                || $row['xzq4'] == $anchang->xzq
                || $row['xzq5'] == $anchang->xzq
            ) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }

            if (($row['xianshi1'] == $anchang->xianshi && empty($row['xzq1']))
                || ($row['xianshi2'] == $anchang->xianshi && empty($row['xzq2']))
                || ($row['xianshi3'] == $anchang->xianshi && empty($row['xzq3']))
                || ($row['xianshi4'] == $anchang->xianshi && empty($row['xzq4']))
                || ($row['xianshi5'] == $anchang->xianshi && empty($row['xzq5']))
            ) {
                $list2[] = array(
                    'id' => $row['id'],
                    'name' => $row['nickname']
                );
                continue;
            }
        }

        $list2 = array_unique($list2, SORT_REGULAR);
        return $list2;
    }

}





